/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import type { OptionsType } from '@/components/_pages/jdk/addLeague/_utils/type';

let dMap: OptionsType[] = [];
let formatResponse = (data: any) => {
  return data;
};
export async function getBrandList(params: any) {
  if (params.formatResponse) {
    formatResponse = params.formatResponse;
    delete params.formatResponse;
  }
  if (dMap.length > 0) {
    return formatResponse(dMap);
  }
  return request('/jdk/Brand/getDelivery', {
    method: 'POST',
    data: params,
  }).then((res) => {
    const { data } = res;
    dMap = formatResponse(
      data.map((item: { name: any; code: any }) => ({
        label: item.name,
        value: item.code,
      })),
    );
    return dMap || [];
  });
}

let sMap: OptionsType[] = [];
export async function getSourceList(params: any) {
  if (sMap.length > 0) {
    return sMap;
  }
  return request('/jdk/Brand/getSource', {
    method: 'POST',
    data: params,
  }).then((res) => {
    const { data } = res;
    sMap = data.map((item: { name: any; code: any }) => ({
      label: item.name,
      value: item.code,
      key: item.code,
    }));
    return sMap || [];
  });
}

export async function getForbidList(params: any) {
  return request('/jdk/delivery/Forbid/getList', {
    method: 'POST',
    data: params,
  });
}

export async function createDelivery(params: any) {
  return request('/jdk/delivery/Forbid/create', {
    method: 'POST',
    data: params,
  });
}

export async function modifyDelivery(params: any) {
  return request('/jdk/delivery/Forbid/modify', {
    method: 'POST',
    data: params,
  });
}

export async function getWhiteList(params: any) {
  return request('/jdk/delivery/Whitelist/getList', {
    method: 'POST',
    data: params,
  });
}

export async function getAreaInfoByBrand(params: any) {
  return request('/jdk/delivery/Forbid/getAreaInfoByBrand', {
    method: 'POST',
    data: params,
  });
}

export async function removeDelivery(params: any) {
  return request('/jdk/delivery/Forbid/remove', {
    method: 'POST',
    data: params,
  });
}

export async function removeWhiteList(params: any) {
  return request('/jdk/delivery/Whitelist/remove', {
    method: 'POST',
    data: params,
  });
}

export async function createWhiteListDelivery(params: any) {
  return request('/jdk/delivery/Whitelist/create', {
    method: 'POST',
    data: params,
  });
}

export async function modifyWhiteListDelivery(params: any) {
  return request('/jdk/delivery/Whitelist/modify', {
    method: 'POST',
    data: params,
  });
}

export async function getLeaguePublishInfo(params: any) {
  return request('/jdk/delivery/LeaguePublishAdvance/getInfo', {
    method: 'POST',
    data: params,
  });
}

export async function getLeaguePublishRemove(params: any) {
  return request('/jdk/delivery/LeaguePublishAdvance/remove', {
    method: 'POST',
    data: params,
  });
}

export async function getLeaguePublishSetting(params: any) {
  return request('/jdk/delivery/LeaguePublishAdvance/setting', {
    method: 'POST',
    data: params,
  });
}

export async function getLeagueList(params: any) {
  return request('/jdk/League/simple', {
    method: 'POST',
    data: params,
  });
}
